'''
Created on 01/06/2010

@author: Glazner
'''
from multiprocessing.managers import BaseManager
import logging
from wp.GLOBALS import *


class Worker(object):
    '''
    Worker class - 
    extend this and implement methods you want to expose to the WorkerPool
    '''

    def execute_remote_task(self,fn,*args,**kw):
        logging.info( 'executing '+str(fn))
        res =  getattr(self, fn)(*args,**kw)
        logging.info(str(fn)+' returned '+str(res))
        return res
    
    def alive(self):
        '''simple function for testing if the server is active
            override if you want...'''
        return True
    
        
    def start(self,port=DEFAULT_PORT,authkey=DEFAULT_KEY):
        RemoteServer.register('get_worker', callable=lambda:self)
        rs = RemoteServer(address=("",port), authkey=authkey)
        self._server = rs.get_server()
        self._server.serve_forever()
        

class RemoteServer(BaseManager):pass

def main():
    Worker().start()


if __name__ =='__main__':
    main()